package me.jessyan.mvparms.demo.mvp.ui.activity.integral;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.view.View;
import android.widget.TextView;

import com.example.xrecyclerview.XRecyclerView;
import com.jess.arms.base.BaseActivity;
import com.jess.arms.base.DefaultAdapter;
import com.jess.arms.di.component.AppComponent;
import com.jess.arms.utils.ArmsUtils;
import com.jess.arms.utils.DoubleClickUtils;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import me.jessyan.mvparms.demo.R;
import me.jessyan.mvparms.demo.di.component.integral.DaggerGiftExchangeComponent;
import me.jessyan.mvparms.demo.di.module.integral.GiftExchangeModule;
import me.jessyan.mvparms.demo.mvp.contract.integral.GiftExchangeContract;
import me.jessyan.mvparms.demo.mvp.presenter.integral.GiftExchangePresenter;
import me.jessyan.mvparms.demo.mvp.ui.adapter.MyGiftExchangeShopAdapter;
import me.jessyan.mvparms.demo.mvp.ui.widget.CustomToolbar;

import static com.jess.arms.utils.Preconditions.checkNotNull;

/**
 * 礼品兑换
 */
public class GiftExchangeActivity extends BaseActivity<GiftExchangePresenter> implements GiftExchangeContract.View {


    @BindView(R.id.toolbar)
    CustomToolbar toolbar;
    @BindView(R.id.my_exchange_tv)
    TextView myExchangeTv;
    @BindView(R.id.recyclerView)
    XRecyclerView recyclerView;

    @Override
    public void setupActivityComponent(@NonNull AppComponent appComponent) {
        DaggerGiftExchangeComponent //如找不到该类,请编译一下项目
                .builder()
                .appComponent(appComponent)
                .giftExchangeModule(new GiftExchangeModule(this))
                .build()
                .inject(this);
    }

    @Override
    public int initView(@Nullable Bundle savedInstanceState) {
        return R.layout.activity_gift_exchange; //如果你不需要框架帮你设置 setContentView(id) 需要自行设置,请返回 0
    }

    @Override
    public void initData(@Nullable Bundle savedInstanceState) {
        initRecyclerView();
        toolbar.setListener(new CustomToolbar.ToolbarListener() {
            @Override
            public void onLeftBack() {
                killMyself();
            }

            @Override
            public void onRightBack() {

            }
        });
    }

    private void initRecyclerView() {
        List<Boolean> list = new ArrayList<>();
        list.add(true);

        list.add(true);
        list.add(true);
        list.add(true);
        list.add(true);
        list.add(false);
        MyGiftExchangeShopAdapter adapter = new MyGiftExchangeShopAdapter(list);
        GridLayoutManager gl = new GridLayoutManager(getApplicationContext(),3 );
        recyclerView.setLayoutManager(gl);
        ArmsUtils.configRecyclerView(recyclerView,gl);

        recyclerView.setAdapter(adapter);

        adapter.setOnItemClickListener(new DefaultAdapter.OnRecyclerViewItemClickListener() {
            @Override
            public void onItemClick(View view, int viewType, Object data, int position) {
                startActivity(new Intent(GiftExchangeActivity.this,GiftDetailsActivity.class));
            }
        });
    }

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public void showMessage(@NonNull String message) {
        checkNotNull(message);
        ArmsUtils.snackbarText(message);
    }

    @Override
    public void launchActivity(@NonNull Intent intent) {
        checkNotNull(intent);
        ArmsUtils.startActivity(intent);
    }

    @Override
    public void killMyself() {
        finish();
    }


    @OnClick({ R.id.my_exchange_tv})
    public void onViewClicked(View view) {
        if(DoubleClickUtils.getInstance().isDouble(view)){
            return;
        }
        switch (view.getId()) {

            case R.id.my_exchange_tv:
                startActivity(new Intent(this,MyExchangeActivity.class));
                break;
                default:
        }
    }
}
